import { Component, OnInit, ViewChild } from "@angular/core";
import { NzModalService, NzModalSubject } from "ng-zorro-antd";
import {
  UserCheckListBean,
  PartyCheckListBean
} from "../bean/register-check.bean";
import { HttpServcie } from "../../../service/http.service";
import { Checkdetail } from "../register-check-detail/register-check-detail";

@Component({
  selector: "register-check-list",
  templateUrl: "register-check-list.html",
  styleUrls: ["register-check-list.scss"]
})
export class Checklist implements OnInit {
  @ViewChild("check") checkDeailPage: Checkdetail;
  giveValue;
  dataFlag;
  modelTitle = "查看审核详情";
  modal: any = 0;
  currentModal: NzModalSubject;
  userList = [];
  partyList = [];
  roleTypeList = [];
  userCheckListBean = new UserCheckListBean();
  partyCheckListBean = new PartyCheckListBean();
  userTable = false;
  partyTable = false;
  isVisible: boolean = false; //模态框
  isConfirmLoading: boolean = false;
  total: string;
  constructor(
    private modalService: NzModalService,
    private httpServcie: HttpServcie
  ) { }

  ngOnInit() {
    this.httpServcie.roleQueryListAll({}).subscribe(data => {
      if (data.status == "200") {
        let ro = [];
        data.data.forEach(element => {
          ro.push({ label: element.roleName, value: element.id });
        });
        this.roleTypeList = ro;
      }
    });
    // 根据回调数据标志判断是详情还是审批
    let permission = window.localStorage.getItem("funcPermissions");
    //获取用户信息判断是超级管理员还是个人用户还是单位
    let user: string = window.localStorage.getItem("user");
    if (user) {
      let userObject = JSON.parse(user);
      //管理员看企业的
      if (userObject["type"] != "party" && userObject["type"] != "user") {
        this.partyTable = true;
        this.partyCheckListBean.pageSize = 10;
        this.partyCheckListBean.currentPage = 1;
        this.queryPartyCheckList();
      }
      //企业看用户的
      if (userObject["type"] == "party") {
        this.userTable = true;
        this.userCheckListBean.pageSize = 10;
        this.userCheckListBean.currentPage = 1;
        this.userCheckListBean.partyId = userObject["partyId"] * 1;
        this.queryUserCheckList();
      }
    }
    // 判断权限是超级管理员还是单位管理员
    // this.userTable = true;
    // if ('') {
    //     this.userTable = true;
    //     this.userCheckListBean.pageSize = 10;
    //     this.userCheckListBean.currentPage = 1;
    //     this.queryUserCheckList();
    // } else if('') {
    //     this.partyTable = true;
    //     this.partyCheckListBean.pageSize = 10;
    //     this.partyCheckListBean.currentPage = 1;
    //     this.queryPartyCheckList();
    // }
  }

  //查看详情
  showDetail(content, flag, footer) {
    this.giveValue = flag;
    //判断是否需要显示审批的确定按钮
    if (this.giveValue["status"] == "1") {
      this.dataFlag = "check";
    } else {
      this.dataFlag = "detail";
    }
    this.currentModal = this.modalService.open({
      title: "查看审核详情",
      content: content,
      width: 1000,
      footer: false,
      style: {
        top: "20px"
      }
    });
  }

  // 查询个人用户注册列表
  queryUserCheckList() {
    this.httpServcie
      .queryUserCheckList(this.userCheckListBean)
      .subscribe(data => {
        if (data.status == "200") {
          this.userList = data.data.list;
          this.total = data.data.total;
        }
      });
  }

  // 查询企业用户注册列表
  queryPartyCheckList() {
    this.httpServcie
      .queryPartyCheckList(this.partyCheckListBean)
      .subscribe(data => {
        if (data.status == "200") {
          this.partyList = data.data.list;
          this.total = data.data.total;
        }
      });
  }

  //分页
  nzPageSizeChange_1(event) {
    this.userCheckListBean.pageSize = event;
    this.userCheckListBean.currentPage = 1;
    this.queryUserCheckList();
  }
  //输入框的方法
  nzPageIndexChange_1(event) {
    this.userCheckListBean.currentPage = event;
    this.queryUserCheckList();
  }
  //当前页
  nzPageIndexClickChange_1(event) {
    this.userCheckListBean.currentPage = event;
    this.queryUserCheckList();
  }

  //分页
  nzPageSizeChange_2(event) {
    this.partyCheckListBean.pageSize = event;
    this.partyCheckListBean.currentPage = 1;
    this.queryPartyCheckList();
  }
  //输入框的方法
  nzPageIndexChange_2(event) {
    this.partyCheckListBean.currentPage = event;
    this.queryPartyCheckList();
  }
  //当前页
  nzPageIndexClickChange_2(event) {
    this.partyCheckListBean.currentPage = event;
    this.queryPartyCheckList();
  }

  //关闭模态框
  callBack(event) {
    this.currentModal.destroy();
    this.ngOnInit();
  }

  // 注：表格最后一列根据每条数据返回的标识显示为‘审批’还是‘详情’；
  //     如果是审批，展示审批页面模态框，审批结束后返回当前列表
  //     如果是详情，展示模态框，展示审批详情及审批意见
}
